$(function(){
	layui.use(['form'],function(){
		var form = layui.form
		  ,layer = layui.layer;
		
		$('#addMenu').click(function(){
			var formData = form.val('menu-form');
			
			var parent_id = $('#parent_id').attr('data-value');
			var menu_name = formData.menu_name;
			var menu_url = formData.menu_url;
			var menu_sort = formData.menu_sort;
			var menu_icon = formData.menu_icon;
			var is_show = formData.is_show;
			
			if(isNull(is_show)){
				is_show = '0';
			}
			
			$.ajax({
				 type : 'post'
				 ,dataType : 'json'
				 ,url : access_url+'/system/systemmanage/addmenu'
				 ,data : {
					 parent_id : parent_id
					 ,menu_name : menu_name
					 ,menu_url : menu_url
					 ,menu_sort : menu_sort
					 ,menu_icon : menu_icon
					 ,is_show : is_show
				 }
				 ,success : function(data){
					layer.closeAll('loading');
					if(data.code != 200){
						layer.msg(data.msg, {icon: 5});
						return;
					}
					parent.layer.alert(data.msg,{icon:6});
					parent.$('#menu_name').val('');
					parent.loadTable();
					parent.layer.closeAll('iframe');
				 }
			 })
		})
	})
})

$('#parent_id').click(function(){
	layer.open({
		type : 2
		,title : '选择父级菜单'
		,area : ['300px','350px']
		,offset : '20px'
		,fixed : false
		,content : 'chooseMenu.html'
		,resize : false
	})
})

function transmitParam(menuInfo){
	console.log("pMenuInfo",menuInfo);
	var parent_id = menuInfo.menu_id;
	var parent_menu_name = menuInfo.menu_name;
	$('#parent_id').attr('data-value',parent_id);
	$('#parent_id').val(parent_menu_name);
}